package net.lesscoding.general;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @author eleven
 * @date 2023/10/10 22:28
 * @apiNote 单向消息发送示例
 */
public class OnewayProducer {
    public static void main(String[] args) throws RemotingException, InterruptedException, MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("pg");
        producer.setNamesrvAddr("192.168.33.129:9876");
        producer.start();
        Message msg = null;
        for (int i = 0; i < 10; i++) {
            byte[] body = String.format("Hi, %d", i).getBytes();
            msg = new Message("someTopic", "someTage", body);
            // 单向发送
            producer.sendOneway(msg);
        }
        producer.shutdown();
        System.out.println("producer shutdown");
    }
}
